package com.example.practice.example;

import com.alibaba.fastjson.JSONObject;
import com.example.practice.model.User;
import com.google.common.collect.Lists;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
import lombok.Data;

import java.util.ArrayList;

/**
 * TODO
 *
 * @author zgq
 * @date 2020/10/15 10:56
 */
@Data
public class XmlStream {

    private User user2;

    public static void main2(String[] args) {
        XStream stream = new XStream(new Xpp3Driver(new NoNameCoder()));
        User user = new User();
        user.setId(1);
        user.setName("ABC");
        String s = stream.toXML(user);
        System.out.println(s);

        XmlStream xmlStream = new XmlStream();
        xmlStream.a();
        String s1 = JSONObject.toJSONString(user);
        User user1 = JSONObject.parseObject(s1, User.class);
        System.out.println(user1);

        ArrayList<String> strings = Lists.newArrayList("a", "b", "c");
        String join = String.join("*", strings);
        System.out.println(join);
    }

    public static void main(String[] args) {
        User user1 = new User();
        user1.setName("A");
        User user2 = a(user1);
        System.out.println(user1);
        System.out.println(user2);

    }

    public static User a(User user) {
        user.setName("b");
        System.out.println(user);
        return user;
    }

    public void a() {
        User user = new User();
        user.setId(1);
        user.setName("ABC");
        setUser2(user);
        System.out.println(user2);
    }
}
